package threadLocalMap;

/**
 * 用泛型构造器赋初始值
 * @author Fang Ruichuan
 * @date 2022-12-28 20:46
 */
public class ThreadLocalDemo {
    static ThreadLocal<Long> x = ThreadLocal.withInitial(() -> {
        System.out.println("Initail Value run...");
        return Thread.currentThread().getId();  // 拿到当前线程ID
    });

    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println("main new Thread线程名:" + Thread.currentThread().getName() + ":" + x.get());
        }).start();
        System.out.println("main 线程名:" + Thread.currentThread().getName() + ":" + x.get());
    }
}
